home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Sources / FWGC.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  9.4 KB  |  383 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWGC.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWGC_H
  13. #include "FWGC.h"
  14. #endif
  15.  
  16. #ifndef FWGRUTIL_H
  17. #include "FWGrUtil.h"
  18. #endif
  19.  
  20. #ifndef FWINK_H
  21. #include "FWInk.h"
  22. #endif
  23.  
  24. #ifndef FWSTYLE_H
  25. #include "FWStyle.h"
  26. #endif
  27.  
  28. // ----- OpenDoc Includes -----
  29.  
  30. #ifndef _FACET_
  31. #include <Facet.h>
  32. #endif
  33.  
  34. #ifndef _SHAPE_
  35. #include <Shape.h>
  36. #endif
  37.  
  38. #ifndef _WINDOW_
  39. #include <Window.h>
  40. #endif
  41.  
  42. #ifndef _PLFMTYPE_
  43. #include <PltmType.h>
  44. #endif
  45.  
  46. #ifndef _TRNSFORM_
  47. #include <Trnsform.h>
  48. #endif
  49.  
  50. #ifndef _CANVAS_
  51. #include <Canvas.h>
  52. #endif
  53.  
  54. #ifndef _CANVAS_
  55. #include <Canvas.h>
  56. #endif
  57.  
  58. #ifndef _EXCEPT_
  59. #include <Except.h>
  60. #endif
  61.  
  62. // ----- Macintosh Includes -----
  63.  
  64. #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
  65. #include <ToolUtils.h>
  66. #endif
  67.  
  68. #if defined(FW_BUILD_MAC) && !defined(__FIXMATH__)
  69. #include <FixMath.h>
  70. #endif
  71.  
  72. #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
  73. #include <math routines.h>
  74. #endif
  75.  
  76. //==============================================================================
  77. //    •• RunTime Info
  78. //==============================================================================
  79.  
  80. #ifdef FW_BUILD_MAC
  81. #pragma segment fwgraphx
  82. #endif
  83.  
  84. //==============================================================================
  85. //    •• class FW_CGraphicContext
  86. //==============================================================================
  87.  
  88. //------------------------------------------------------------------------------
  89. //    • FW_CGraphicContext::FW_CGraphicContext
  90. //------------------------------------------------------------------------------
  91.  
  92. FW_CGraphicContext::FW_CGraphicContext(XMPFacet *xmpFacet, XMPShape* clipShape) :
  93.     fWindowFocus(FALSE),
  94.     fXMPFacet(xmpFacet),
  95.     fXMPCanvas(xmpFacet->GetCanvas()),
  96.     fInkSeed(0),
  97.     fStyleSeed(0),
  98.     fForceSelect(FALSE),
  99.     fPreviousGraphicContext(gGraphicGlobales.gLastGC)
  100. {
  101. #ifdef FW_BUILD_MAC
  102.     ::GetPort(&fPreviousPort);
  103.  
  104.     ::SetPort(fXMPCanvas->GetPlatformCanvas());
  105.  
  106.     fCurOrigin.h = XMPASLMQDGlobals.thePort->portRect.left;
  107.     fCurOrigin.v = XMPASLMQDGlobals.thePort->portRect.top;
  108.  
  109.     fOldClip = NewRgn();
  110.     ::GetClip(fOldClip);
  111.     
  112.     ::SetClip(clipShape ? clipShape->GetQDRegion() : fXMPFacet->GetAggregateClipShape()->GetQDRegion());
  113.  
  114.     FW_CPoint offset(0,0);
  115.     offset = fXMPFacet->GetContentTransform()->TransformPoint(offset);
  116.     ::SetOrigin(-(offset.IntX()), -(offset.IntY()));    
  117. #endif
  118.  
  119. #ifdef FW_BUILD_WIN
  120. #endif
  121.  
  122.     gGraphicGlobales.gLastGC = this;
  123. }
  124.  
  125. //------------------------------------------------------------------------------
  126. //    • FW_CGraphicContext::FW_CGraphicContext
  127. //------------------------------------------------------------------------------
  128.  
  129. FW_CGraphicContext::FW_CGraphicContext(XMPWindow* xmpWindow) :
  130.     fWindowFocus(TRUE),
  131.     fXMPFacet(xmpWindow->GetRootFacet()),
  132.     fXMPCanvas(fXMPFacet->GetCanvas()),
  133.     fInkSeed(0),
  134.     fStyleSeed(0),
  135.     fForceSelect(FALSE),
  136.     fPreviousGraphicContext(gGraphicGlobales.gLastGC)
  137. {
  138.  
  139. #ifdef FW_BUILD_MAC
  140.     ::GetPort(&fPreviousPort);
  141.  
  142.     ::SetPort(fXMPCanvas->GetPlatformCanvas());
  143.  
  144.     fCurOrigin.h = XMPASLMQDGlobals.thePort->portRect.left;
  145.     fCurOrigin.v = XMPASLMQDGlobals.thePort->portRect.top;
  146.  
  147.     fOldClip = ::NewRgn();
  148.     ::GetClip(fOldClip);
  149.  
  150.     ::SetOrigin(0, 0);
  151.     
  152.     ::ClipRect(&XMPASLMQDGlobals.thePort->portRect);
  153. #endif
  154.  
  155. #ifdef FW_BUILD_WIN
  156. #endif
  157.  
  158.     gGraphicGlobales.gLastGC = this;
  159. }
  160.  
  161. //------------------------------------------------------------------------------
  162. //    • FW_CGraphicContext::~FW_CGraphicContext
  163. //------------------------------------------------------------------------------
  164.  
  165. FW_CGraphicContext::~FW_CGraphicContext()
  166. {
  167.     InvalidPreviousGCCache();        // Force selection of the previous gc with the same canvas        
  168.  
  169. #ifdef FW_BUILD_MAC        
  170.     // ----- Restore previous grafport and origin -----
  171.     ::SetOrigin(fCurOrigin.h, fCurOrigin.v);
  172.     ::SetClip(fOldClip);
  173.     ::DisposeRgn(fOldClip);
  174.     fOldClip = NULL;
  175.  
  176.     ::PenNormal();
  177.     ::RGBForeColor(&FW_kRGBBlack);
  178.     ::RGBBackColor(&FW_kRGBWhite);
  179.     
  180.     ::SetPort(fPreviousPort);
  181. #endif
  182.  
  183. #ifdef FW_BUILD_WIN    
  184. #endif
  185.  
  186.     gGraphicGlobales.gLastGC = fPreviousGraphicContext;
  187. }
  188.  
  189. //------------------------------------------------------------------------------
  190. //    • FW_CGraphicContext::AsPlatformPoint
  191. //------------------------------------------------------------------------------
  192.  
  193. FW_SPlatformPoint FW_CGraphicContext::AsPlatformPoint(const FW_CPoint& point)
  194. {
  195.     FW_SPlatformPoint pt;
  196.     
  197. #ifdef FW_BUILD_MAC
  198.     pt.h = FixedToInt(point.x);
  199.     pt.v = FixedToInt(point.y);
  200. #endif
  201.  
  202. #ifdef FW_BUILD_MAC
  203. #endif
  204.  
  205.     return pt;
  206. }
  207.  
  208. //------------------------------------------------------------------------------
  209. //    • FW_CGraphicContext::AsPlatformRect
  210. //------------------------------------------------------------------------------
  211.  
  212. FW_SPlatformRect FW_CGraphicContext::AsPlatformRect(const FW_CRect& rect)
  213. {
  214.     FW_SPlatformRect r;
  215.     
  216. #ifdef FW_BUILD_MAC
  217.     ::SetRect(&r, FixedToInt(rect.left), FixedToInt(rect.top), FixedToInt(rect.right), FixedToInt(rect.bottom));
  218. #endif
  219.  
  220. #ifdef FW_BUILD_WIN
  221. #endif
  222.  
  223.     return r;
  224. }
  225.  
  226. //------------------------------------------------------------------------------
  227. //    • FW_CGraphicContext::AsPlatformRegion
  228. //------------------------------------------------------------------------------
  229.  
  230. FW_PlatformRegion FW_CGraphicContext::AsPlatformRegion(XMPShape* shape)
  231. {
  232. #ifdef FW_BUILD_MAC
  233.     return shape->GetQDRegion();
  234. #endif
  235. #ifdef FW_BUILD_WIN
  236. #endif
  237. }
  238.  
  239. //------------------------------------------------------------------------------
  240. //    • FW_CGraphicContext::GetClipShape
  241. //------------------------------------------------------------------------------
  242.  
  243. void FW_CGraphicContext::GetClipShape(XMPShape* clipShape)
  244. {
  245. #ifdef FW_BUILD_MAC
  246.     XMPRgnHandle clip = ::NewRgn();
  247.     ::GetClip(clip);
  248.     clipShape->SetQDRegion(clip);
  249. #endif
  250. #ifdef FW_BUILD_WIN
  251. #endif
  252. }
  253.  
  254. //------------------------------------------------------------------------------
  255. //    • FW_CGraphicContext::SetClipShape
  256. //------------------------------------------------------------------------------
  257. //    SetClipShape uses a copy of the shape
  258.  
  259. void FW_CGraphicContext::SetClipShape(XMPShape* clipShape)
  260. {
  261. #ifdef FW_BUILD_MAC
  262.     ::SetClip(clipShape->GetQDRegion());
  263. #endif
  264.  
  265. #ifdef FW_BUILD_MAC
  266. #endif
  267. }
  268.  
  269. //------------------------------------------------------------------------------
  270. //    • FW_CGraphicContext::InvalidPreviousGCCache
  271. //------------------------------------------------------------------------------
  272. // Look for a previous FW_CGraphicContext with the same canvas and set its
  273. // fForceSelect flag to true.
  274.  
  275. void FW_CGraphicContext::InvalidPreviousGCCache()
  276. {
  277.     FW_CGraphicContext* gc = fPreviousGraphicContext;
  278.     
  279.     while (gc != NULL)
  280.     {
  281.         if (gc->GetCanvas() == fXMPCanvas)
  282.         {
  283.             gc->fForceSelect = TRUE;
  284.             return;
  285.         }
  286.         
  287.         gc = gc->fPreviousGraphicContext;
  288.     }
  289. }
  290.  
  291. //------------------------------------------------------------------------------
  292. //    • FW_CGraphicContext::SyncGraphicContext
  293. //------------------------------------------------------------------------------
  294.  
  295. void FW_CGraphicContext::SyncGraphicContext(XMPShape* clipShape)
  296. {
  297. #ifdef FW_BUILD_MAC
  298.     ::SetPort(fXMPCanvas->GetPlatformCanvas());
  299.  
  300.     if (clipShape)
  301.     {
  302.         ::SetClip(clipShape->GetQDRegion());
  303.     }
  304.     else
  305.     {
  306.         if (fWindowFocus)
  307.             ::ClipRect(&XMPASLMQDGlobals.thePort->portRect);
  308.         else
  309.             ::SetClip(fXMPFacet->GetAggregateClipShape()->GetQDRegion());        
  310.     }
  311.     
  312.     FW_CPoint offset(0,0);
  313.     
  314.     if (!fWindowFocus)
  315.         offset = fXMPFacet->GetContentTransform()->TransformPoint(offset);
  316.         
  317.     ::SetOrigin(-(offset.IntX()), -(offset.IntY()));
  318.     
  319.     ::PenNormal();
  320.     
  321.     fForceSelect = TRUE;
  322. #endif
  323. }
  324.  
  325. #ifdef FW_BUILD_MAC
  326. //------------------------------------------------------------------------------
  327. //    • FW_CGraphicContext::SelectInkAndStyle
  328. //------------------------------------------------------------------------------
  329.  
  330. void FW_CGraphicContext::SelectInkAndStyle(FW_CInk ink, FW_CStyle style, FW_ShapeCategory shapeCategory, FW_ShapeFills shapeFill)
  331. {
  332. FW_UNUSED(shapeFill);
  333.  
  334.     WASSERTM((const void*)ink != NULL, "Can't select a null ink");
  335.     WASSERTM((const void*)style != NULL, "Can't select a null style");
  336.  
  337.     if (fForceSelect || ink->GetSeed() != fInkSeed || fShapeCategory != shapeCategory)
  338.     {
  339.         fInkSeed = ink->GetSeed();
  340.         fShapeCategory = shapeCategory;
  341.         ink->SelectInGC(this, shapeCategory);
  342.     }
  343.  
  344.     if (fForceSelect || style->GetSeed() != fStyleSeed || fShapeCategory != shapeCategory)
  345.     {
  346.         fStyleSeed = style->GetSeed();
  347.         fShapeCategory = shapeCategory;
  348.         style->SelectInGC(this, shapeCategory);
  349.     }
  350.     
  351.     fForceSelect = FALSE;
  352. }
  353.  
  354. #endif
  355.  
  356. #ifdef FW_BUILD_WIN
  357. //------------------------------------------------------------------------------
  358. //    • FW_CGraphicContext::SelectInkAndStyle
  359. //------------------------------------------------------------------------------
  360.  
  361. void FW_CGraphicContext::SelectInkAndStyle(FW_CInk ink, FW_CStyle style, FW_ShapeCategory shapeCategory, FW_ShapeFills shapeFill)
  362. {    
  363.     WASSERTM((const void*)ink != NULL, "Can't select a null ink");
  364.     WASSERTM((const void*)style != NULL, "Can't select a null style");
  365.     
  366.     if (fForceSelect || ink->GetSeed() != fInkSeed || fInkShapeCategory != shapeCategory)
  367.     {
  368.         fInkSeed = ink->GetSeed();
  369.         fInkShapeCategory = shapeCategory;
  370.         ink->SelectInGC(this, shapeCategory);
  371.     }
  372.  
  373.     if (fForceSelect || style->GetSeed() != fStyleSeed || fStyleShapeCategory != shapeCategory)
  374.     {
  375.         fStyleSeed = style->GetSeed();
  376.         fStyleShapeCategory = shapeCategory;
  377.         style->SelectInGC(this, shapeCategory);
  378.     }
  379.     
  380.     fForceSelect = FALSE;
  381. }
  382. #endif
  383.